package com.digitalchina.lxnsy.viewholder;

import android.app.Activity;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessPersonnelService;
import com.digitalchina.lxnsy.entity.PersonnelDemandVO;
import com.digitalchina.lxnsy.interfaces.IMyNhbPos;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.toolkit.Utils;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;



/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：郑皓
 * 创建时间：2017/9/8 17:18
 * 修改备注：
 * ================================================
 */
public class PersonnelServiceHolder extends BaseViewHolder<PersonnelDemandVO> {

    //private Map<String, Object> map = new HashMap<>();

    private SimpleDraweeView sdvHead; // 头像
    private TextView tvTitle; // 发布内容
    private TextView tvName; // 用户名
    private TextView tvTime; // 发布时间
    private TextView tvPrice; // 人员单价
    private TextView tvDemandName; // 招聘要求
    private TextView tvStartDate; // 工作时间 开始-结束
    private TextView tvAddress; // 地址
    private TextView tvTel; // 打电话
    private TextView tvTag; // 需求or人力
    private LinearLayout layout; // 打电话 聊一聊 layout
    private LinearLayout layoutWorkTime; // 工作时间 layout

    private RelativeLayout layoutEditAndDel;
    private TextView tvEdit;
    private TextView tvDel;

    private boolean myTalents;
    private String postType; // 0-发布需求 1-发布人力

    private IMyNhbPos iMyNhbPos;


    public PersonnelServiceHolder(ViewGroup parent, boolean myTalents, String postType, IMyNhbPos iMyNhbPos) {
        super(parent, R.layout.item_personnel_service);
        this.myTalents = myTalents;
        this.postType = postType;
        this.iMyNhbPos = iMyNhbPos;
        sdvHead = $(R.id.iv_head);
        tvTitle = $(R.id.tv_title);
        tvName = $(R.id.tv_name);
        tvTag = $(R.id.tv_tv_demand_tag);
        tvTime = $(R.id.tv_time);
        tvPrice = $(R.id.tv_price);
        tvDemandName = $(R.id.tv_demand_name);
        tvStartDate = $(R.id.tv_start_date);
        tvAddress = $(R.id.tv_address);
        tvTel = $(R.id.tv_tel);
        layout = $(R.id.layout_chat_tel);
        layoutWorkTime = $(R.id.layout_work_time);

        layoutEditAndDel = $(R.id.layout_edit_and_del);
        tvEdit = $(R.id.tv_edit);
        tvDel = $(R.id.tv_del);

    }

    @Override
    public void setData(final PersonnelDemandVO data) {
        super.setData(data);

        if (postType.equals("0")) {
            tvTag.setText("招聘需求：");
            //map.put("postType", "editDemand");
        } else {
            tvTag.setText("招聘需求：");
            //map.put("postType", "editSupply");
        }

        if (myTalents) {
            layout.setVisibility(View.GONE);
            layoutEditAndDel.setVisibility(View.VISIBLE);

            tvEdit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
//                    map.put("data", data);
//                    GotoUtil.gotoActivity((Activity) getContext(), PostDemandActivity.class, "map", map);
                    iMyNhbPos.edit(getAdapterPosition());
                }
            });
            tvDel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    iMyNhbPos.del(getAdapterPosition());
                }
            });
        } else {
            layout.setVisibility(View.VISIBLE);
            layoutEditAndDel.setVisibility(View.GONE);
        }


        FrescoUtil.showImageSmall("", sdvHead);
        tvTitle.setText(data.getContent() + "");
        tvName.setText(data.getContacts() + "");
        tvTime.setText(data.getUpdateTime());

        if (data.getStartDate() != null && data.getEndDate() != null) {
            layoutWorkTime.setVisibility(View.VISIBLE);
            tvStartDate.setText(data.getStartDate()+ "至" + data.getEndDate());
        } else {
            layoutWorkTime.setVisibility(View.GONE);
        }



        tvPrice.setText(data.getPrice() + "元/人天");
        tvDemandName.setText(data.getDemand() != null ? data.getDemand() : "面谈");

        tvAddress.setText(data.getAddress());

        if (StringUtil.isStrEmpty(data.getTelephone()))
            tvTel.setVisibility(View.INVISIBLE);
        else
            tvTel.setVisibility(View.VISIBLE);
        tvTel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Utils.callPhone(getContext(), data.getTelephone());
                BusinessPersonnelService.saveTelOperation((Activity) getContext(), data.getId(), new Handler());
            }
        });
    }

}
